package com.bsh.repository;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import com.bsh.mybatis.IRepository.VerifySmsMapper;
import com.bsh.mybatis.model.VerifySms;




@Repository
public class DaoVerifySms {
	@Resource
	SqlSessionTemplate session;
	@Resource
	JdbcTemplate jdbcTemplate;
	@Resource
	NamedParameterJdbcTemplate namedJdbcTemplate;
	
	VerifySmsMapper getMapper() {
		return session.getMapper(VerifySmsMapper.class);
	}
	
	public int deleteByPrimaryKey(Integer id) {
		int res = getMapper().deleteByPrimaryKey(id);
		return res;
	}

	public int insert(VerifySms record) {
		int res = getMapper().insert(record);
		return record.getId();
	}

	public int insertSelective(VerifySms record) {
		int res = getMapper().insertSelective(record);
		return record.getId();
	}

	public VerifySms selectByPrimaryKey(Integer id) {
		VerifySms row = getMapper().selectByPrimaryKey(id);
		return row;
	}

	public int updateByPrimaryKeySelective(VerifySms record) {
		int res = getMapper().updateByPrimaryKeySelective(record);
		return res;
	}

	public int updateByPrimaryKey(VerifySms record) {
		int res = getMapper().updateByPrimaryKey(record);
		return res;
	}
	
	public VerifySms selectByUuid(String uuid) {
		VerifySms res = getMapper().selectByUuid(uuid);
		return res;
	}

	/**
	 * 删除过期记录
	 */
	public void  delete(){
		String sql="DELETE FROM  verify_sms where create_time < DATE_SUB(NOW(),INTERVAL  CAST((SELECT svalue from sys_config WHERE skey='sms_uuid_effect' LIMIT 1) AS SIGNED INTEGER) MINUTE)";
		jdbcTemplate.execute(sql);
	}


	
}
